package com.ymatou.iapi.shoppingcart.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.shoppingcart.parameter.GetShoppingCartCountBean;
import com.ymatou.iapi.shoppingcart.service.GetShoppingCartCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.mongo.ShoppingCartMongoWapper;

public class Ts_GetShoppingCartCount {
	
	private static GetShoppingCartCountBean getShoppingCartCountBean;
	private static GetShoppingCartCountCall getShoppingCartCountCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取购物车数量");
	}

	@Before
	public void caseUp() throws Exception {
		getShoppingCartCountBean = new GetShoppingCartCountBean();
		getShoppingCartCountCall = new GetShoppingCartCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getShoppingCartCountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Ts_GetShoppingCartCount_001() {
		 Logger.start(true,"判断接口status是否为200");
		 try {
			 getShoppingCartCountBean.setUserId(4085);
			 getShoppingCartCountBean.setClearInvalid(true);
			 
			 getShoppingCartCountCall.setData(getShoppingCartCountBean);
			 getShoppingCartCountCall.callService();
			 
			 int status = getShoppingCartCountCall.getStatus();
			 
			 Logger.comment("getShoppingCartCountCall send:" + getShoppingCartCountCall.getEntityString());
			 Logger.comment("getShoppingCartCountCall response:" + getShoppingCartCountCall.getReturnData());
			 
				
			 Logger.verifyEquals(200, status, "判断接口status是否为200");		
			 
		 } catch (Exception e) {
			 Logger.fail(e);
		 }
	 }
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Ts_GetShoppingCartCount_002() {
		 Logger.start(true,"验证result是否为空");
		 try {
			 getShoppingCartCountBean.setUserId(4085);
			 getShoppingCartCountBean.setClearInvalid(true);
			 
			 getShoppingCartCountCall.setData(getShoppingCartCountBean);
			 getShoppingCartCountCall.callService();
			 
			 Logger.comment("addShoppingCartCall send:" + getShoppingCartCountCall.getEntityString());
			 Logger.comment("addShoppingCartCall response:" + getShoppingCartCountCall.getReturnData());
			 
			 Logger.verifyNotNull(getShoppingCartCountCall.getResult(), "验证result是否为空");
		 } catch (Exception e) {
			 Logger.fail(e);
		 }
	 }
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Ts_GetShoppingCartCount_003() {
		 Logger.start(true,"验证购物车数量是否与mongodb一致");
		 try {
			 getShoppingCartCountBean.setUserId(4085);
			 getShoppingCartCountBean.setClearInvalid(true);
			 
			 getShoppingCartCountCall.setData(getShoppingCartCountBean);
			 getShoppingCartCountCall.callService();
			 
			 int totalNum = getShoppingCartCountCall.getResult().getInt("totalNum");
			 
			 ShoppingCartMongoWapper shoppingCartMongoWapper = new ShoppingCartMongoWapper();
			 
			 Logger.comment("getShoppingCartCountCall send:" + getShoppingCartCountCall.getEntityString());
			 Logger.comment("getShoppingCartCountCall response:" + getShoppingCartCountCall.getReturnData());
			 
			 Logger.verifyEquals(shoppingCartMongoWapper.selectShoppingInfo(4085, 101).size(), totalNum, "验证购物车数量是否与mongodb一致");
		 } catch (Exception e) {
			 Logger.fail(e);
		 }
	 }
}
